package com.fbli.controller;

import com.fbli.entity.Result;
import com.fbli.pojo.Consult;
import com.fbli.pojo.GoodsOrder;
import com.fbli.pojo.Knowledge;
import com.fbli.service.ConsultService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/consult")
public class ConsultController {
    @Autowired
    private ConsultService consultService;
    @RequestMapping("/selectPage")
    public PageInfo<Consult> selectPage(@RequestBody Consult consult, int pageNum, int pageSize){
        return consultService.selectPage(consult,pageNum,pageSize);
    }
    @RequestMapping("/insert")
    public Result insert(@RequestBody Consult consult){
        try {
            consultService.insert(consult);
            return new Result(true,"成功");
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,"异常，失败");
        }
    }
    @RequestMapping("/deleteByPrimaryKey")
    public Result deleteByPrimaryKey( long[] consultIds){
        System.out.println("deleteByPrimaryKey+controller"+consultIds);
        try {
            consultService.deleteByPrimaryKey(consultIds);
            return new Result(true,"成功");
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,"异常，失败");
        }
    }
    @RequestMapping("/updateByPrimaryKey")
    public Result updateByPrimaryKey(@RequestBody Consult record){
        System.out.println("1234"+record);
        try {
            consultService.updateByPrimaryKey(record);
            return new Result(true,"成功");
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,"异常，失败");
        }
    }
    @RequestMapping("/selectByPrimaryKey")
    public Consult selectByPrimaryKey(int consultId){
        return consultService.selectByPrimaryKey(consultId);
    }
    @RequestMapping("/selectAll")
    public Result selectAll(){
        try {
            consultService.selectAll();
            return new Result(true,"成功");
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,"异常，失败");
        }
    }
    @RequestMapping("/selectConsult")
    public Result selectConsult(@RequestBody String keyword){
        try {
            consultService.selectConsult(keyword);
            return new Result(true,"成功");
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,"异常，失败");
        }
    }
}
